// pages/csregistration/csregistration.js
var util = require("../../utils/util.js")
var api = require("../../utils/api.js")
var app = getApp();
const device = wx.getSystemInfoSync()
const W = device.windowWidth
const H = device.windowHeight - 50
let cropper = require('../../utils/welCropper/welCropper.js');
var a = false
Page({

    /**
     * 页面的初始数据
     */
    data: {
        whether: 0,
        step: 1,
        qualificationtext: '',
        qualificationnum: '',
        qualificationphotos: [],
        idCardphotos: [],
        workperiod: '',
        workyear: '',
        personperiod: '',
        infotype: 1,
        accountid: 0,
        psy_consult: {},
        factions_list: {},
        tag_list: {},
        tag_type_list: {},
        tags_time: {},
        record: {},
        avatar: '../res/0010.png',
        goodat_ids: {},
        qualification: 0,
        price: '',
        type_ids: {},
        factions_ids: {},
        ntype_ids: '',
        nfactions_ids: '',
        ngoodat_ids: '',
        nperiod_ids: '',
        intro: '',
        islow: 0,
        priceintro: '',
        forviewer: '',
        worktype: '',
        period_ids: {},
        arealist: {}, //省
        citylist: {}, //省
        provincename: '请选择省', //省
        cityname: '请选择市', //省
        province_id: 0,
        city_id: 0,
        name: '',
        consultid: 0,
        education: {},
        train: {},
        addtype: 0,
        start_date: '',
        end_date: '',
        school: '',
        major: '',
        educate: '',
        id: '',
        educatephotos: [],
        qualificatephotos: [],
        trainphotos: [],
        pexpphotos: [],
        supexpphotos: [],
        pexps: {},
        hours: '',
        forwards: '',
        supname: '',
        leading: '',
        leadname: '',
        leadphone: '',
        supexps: {},
		isread:0,
		theme: '',
		leader: '',
        items: [{
                name: '1',
                value: '是',
                checked: 'selected'
            },
            {
                name: '2',
                value: '否'
            },
        ],
    },
	leaderInput(e){
		
		this.setData({
			leader: e.detail.value 
		})
	},
	themeInput(e) {
		this.setData({
			theme: e.detail.value
		})
	},
    qualificationInput: function(e) {
        this.setData({
            qualificationtext: e.detail.value
        })
    },
    qualificationNumInput: function(e) {
        this.setData({
            qualificationnum: e.detail.value
        })
    },
    workperiodInput: function(e) {
        this.setData({
            workperiod: e.detail.value
        })
    },
    workyearInput: function(e) {
        this.setData({
            workyear: e.detail.value
        })
    },
    personperiodInput: function(e) {
        this.setData({
            personperiod: e.detail.value
        })
    },
    nameInput: function(e) {
        this.setData({
            name: e.detail.value
        })
    },
    mytouchstart: function(e) {
        this.setData({
            touch_start: e.timeStamp
        })
    },
    mytouchend: function(e) {
        this.setData({
            touch_end: e.timeStamp
        })
    },
    addimg: function(e) {
        let that = this
        a = true
        let type = e.currentTarget.dataset.type

        if (type == 'educate') {
            api.chooseimage(9, that.data.educatephotos, 'file', app.u.HOME_URL + app.u.UPLOADIMG).then(res => {
                if (that.data.educatephotos[0]) {
                    that.setData({
                        educatephotos: that.data.educatephotos.concat(res)
                    })
                } else {
                    that.setData({
                        educatephotos: res
                    })
                }
            })
        } else if (type == 'qualificate') {
            api.chooseimage(9, that.data.qualificatephotos, 'file', app.u.HOME_URL + app.u.UPLOADIMG).then(res => {
                if (that.data.qualificatephotos[0]) {
                    that.setData({
                        qualificatephotos: that.data.qualificatephotos.concat(res)
                    })
                } else {
                    that.setData({
                        qualificatephotos: res
                    })
                }
            })
        } else if (type == 'train') {
            api.chooseimage(9, that.data.trainphotos, 'file', app.u.HOME_URL + app.u.UPLOADIMG).then(res => {
                if (that.data.trainphotos[0]) {
                    that.setData({
                        trainphotos: that.data.trainphotos.concat(res)
                    })
                } else {
                    that.setData({
                        trainphotos: res
                    })
                }
            })
        } else if (type == 'pexp') {
            api.chooseimage(9, that.data.pexpphotos, 'file', app.u.HOME_URL + app.u.UPLOADIMG).then(res => {
                if (that.data.pexpphotos[0]) {
                    that.setData({
                        pexpphotos: that.data.pexpphotos.concat(res)
                    })
                } else {
                    that.setData({
                        pexpphotos: res
                    })
                }
            })
        } else if (type == 'supexp') {
            api.chooseimage(9, that.data.supexpphotos, 'file', app.u.HOME_URL + app.u.UPLOADIMG).then(res => {
                if (that.data.supexpphotos[0]) {
                    that.setData({
                        supexpphotos: that.data.supexpphotos.concat(res)
                    })
                } else {
                    that.setData({
                        supexpphotos: res
                    })
                }
            })
        }
    },
    addidCardphotos: function() {
        let that = this
        a = true
        api.chooseimage(2, that.data.idCardphotos, 'file', app.u.HOME_URL + app.u.UPLOADIMG).then(res => {
            console.log(res)
            that.setData({
                idCardphotos: that.data.idCardphotos.concat(res)
            })
        })
    },
    giftview: function(e) {
        a = true
        let type = e.currentTarget.dataset.type
        let touchTime = this.data.touch_end - this.data.touch_start
        if (type == 'educate') {
            if (touchTime > 350) {
                let that = this
                let images = that.data.educatephotos
                var index = e.currentTarget.dataset.index
                wx.showModal({
                    title: '提示',
                    content: '确定要删除此图片吗？',
                    success(res) {
                        if (res.confirm) {
                            images.splice(index, 1)
                            that.setData({
                                educatephotos: images
                            })
                        } else if (res.cancel) {
                            console.log('用户点击取消')
                        }
                    }
                })
            } else {
                wx.previewImage({
                    current: e.currentTarget.dataset.url,
                    urls: this.data.educatephotos
                })
            }
        } else if (type == 'qualificate') {
            if (touchTime > 350) {
                let that = this
                let images = that.data.qualificationphotos
                var index = e.currentTarget.dataset.index
                wx.showModal({
                    title: '提示',
                    content: '确定要删除此图片吗？',
                    success(res) {
                        if (res.confirm) {
                            images.splice(index, 1)
                            that.setData({
                                qualificationphotos: images
                            })
                        } else if (res.cancel) {
                            console.log('用户点击取消')
                        }
                    }
                })
            } else {
                wx.previewImage({
                    current: e.currentTarget.dataset.url,
                    urls: this.data.qualificationphotos
                })
            }

        } else if (type == 'train') {

            if (touchTime > 350) {
                let that = this
                let images = that.data.trainphotos
                var index = e.currentTarget.dataset.index
                wx.showModal({
                    title: '提示',
                    content: '确定要删除此图片吗？',
                    success(res) {
                        if (res.confirm) {
                            images.splice(index, 1)
                            that.setData({
                                trainphotos: images
                            })
                        } else if (res.cancel) {
                            console.log('用户点击取消')
                        }
                    }
                })
            } else {
                wx.previewImage({
                    current: e.currentTarget.dataset.url,
                    urls: this.data.trainphotos
                })
            }
        } else if (type == 'pexp') {
            if (touchTime > 350) {
                let that = this
                let images = that.data.pexpphotos
                var index = e.currentTarget.dataset.index
                wx.showModal({
                    title: '提示',
                    content: '确定要删除此图片吗？',
                    success(res) {
                        if (res.confirm) {
                            images.splice(index, 1)
                            that.setData({
                                pexpphotos: images
                            })
                        } else if (res.cancel) {
                            console.log('用户点击取消')
                        }
                    }
                })
            } else {
                wx.previewImage({
                    current: e.currentTarget.dataset.url,
                    urls: this.data.pexpphotos
                })
            }
        } else if (type == 'supexp') {

            if (touchTime > 350) {
                let that = this
                let images = that.data.supexpphotos
                var index = e.currentTarget.dataset.index
                wx.showModal({
                    title: '提示',
                    content: '确定要删除此图片吗？',
                    success(res) {
                        if (res.confirm) {
                            images.splice(index, 1)
                            that.setData({
                                supexpphotos: images
                            })
                        } else if (res.cancel) {
                            console.log('用户点击取消')
                        }
                    }
                })
            } else {
                wx.previewImage({
                    current: e.currentTarget.dataset.url,
                    urls: this.data.supexpphotos
                })
            }
        }
    },
    giftview2: function(e) {
        a = true
        let touchTime = this.data.touch_end - this.data.touch_start
        if (touchTime > 350) {
            let that = this
            let images = that.data.idCardphotos
            var index = e.currentTarget.dataset.index
            wx.showModal({
                title: '提示',
                content: '确定要删除此图片吗？',
                success(res) {
                    if (res.confirm) {
                        images.splice(index, 1)
                        that.setData({
                            idCardphotos: images
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消')
                    }
                }
            })
        } else {
            wx.previewImage({
                current: e.currentTarget.dataset.url,
                urls: this.data.idCardphotos
            })
        }
    },
    bindProvinceChange: function(e) {
        this.setData({
            province_id: this.data.arealist[e.detail.value].area_id,
            provincename: this.data.arealist[e.detail.value].area_name,
        })
        this.getarealist()
    },
    getarealist: function() {
        let url3 = app.u.HOME_URL + app.u.GET_AREA_LIST
        let data3 = { province: this.data.province_id }
        api.requestUrl(data3, url3).then(res => {
            if (res.code == 200) {
                this.setData({
                    city_id: res.data[0].area_id,
                    cityname: res.data[0].area_name
                })
                this.setData({
                    citylist: res.data
                })
            } else {
                api.showError(res.msg)
            }
        })
    },
    bindCityChange: function(e) {
        this.setData({
            city_id: this.data.citylist[e.detail.value].area_id,
            cityname: this.data.citylist[e.detail.value].area_name
        })
    },
    bindPickerChange: function(e) {
        this.setData({
            qualification: this.data.tag_list[e.detail.value].id,
            qualificationtext: this.data.tag_list[e.detail.value].name
        })
    },
    radioChange: function(e) {
        this.setData({
            whether: e.detail.value
        })
    },
    priceInput: function(e) {
        this.setData({
            price: e.detail.value
        })
    },
    period_idsChange: function(e) {
        this.setData({
            nperiod_ids: e.detail.value.join(',')
        })
    },
    type_idsChange: function(e) {
        this.setData({
            ntype_ids: e.detail.value.join(',')
        })
    },
    goodat_idsChange: function(e) {
        this.setData({
            ngoodat_ids: e.detail.value.join(',')
        })
    },
    factions_idsChange: function(e) {
        this.setData({
            nfactions_ids: e.detail.value.join(',')
        })
    },
    worktypeInput: function(e) {
        this.setData({
            worktype: e.detail.value
        })
    },
    priceinfoInput: function(e) {
        this.setData({
            priceintro: e.detail.value
        })
    },
    forviwerInput: function(e) {
        this.setData({
            forviewer: e.detail.value
        })
    },
    steponeinfo: function() {
        let that = this

        if (that.data.name === '') {
            api.showError('请填写姓名')
            return false
        }
        if (that.data.province_id === 0) {
            api.showError('请选择省份')
            return false
        }
        if (that.data.city_id === 0) {
            api.showError('请选择城市')
            return false
        }
		if (that.data.isread == 0) {
			api.showError('请先同意协议')
			return false
		}
        // if (that.data.price === '0') {
        //     api.showError('请填写咨询费用')
        //     return false
        // }
        // if (that.data.qualificationtext === '') {
        //     api.showError('请填写资质')
        //     return false
        // }
        // if (that.data.qualificationphotos === '') {
        //     api.showError('请上传资质图片')
        //     return false
        // }
        // if (that.data.ntype_ids === '') {
        //     api.showError('请选择咨询方式')
        //     return false
        // }
        // if (that.data.nperiod_ids === '') {
        //     api.showError('请选择咨询时段')
        //     return false
        // }
        // if (that.data.ngoodat_ids === '') {
        //     api.showError('请选择擅长类型')
        //     return false
        // }
        if (that.data.nfactions_ids === 0) {
            api.showError('请选择咨询流派')
            return false
        }
        // if (that.data.workperiod === '') {
        //     api.showError('请填写活跃时段')
        //     return false
        // }
        if (that.data.workyear === '') {
            api.showError('请填写工作年限')
            return false
        }
        if (that.data.personperiod === '') {
            api.showError('请填写个人体验时间')
            return false
        }
        if (that.data.idCardphotos === '') {
            api.showError('请上传身份证照片')
            return false
        }
        let data = {
            consultid: that.data.consultid,
            account_id: that.data.accountid,
            avatar: that.data.avatar,
            name: that.data.name,
            // qualification: that.data.qualification,
            // price: that.data.price,
            // type_ids: that.data.ntype_ids,
            factions_ids: that.data.nfactions_ids,
            // period_ids: that.data.nperiod_ids,
            // goodat_ids: that.data.ngoodat_ids,
            // islow: that.data.islow,
            // forviewer: that.data.forviewer,
            // worktype: that.data.worktype,
            // priceintro: that.data.priceintro,
            province_id: that.data.province_id,
            city_id: that.data.city_id,
            // qualificationphotos: that.data.qualificationphotos.join(','),
            // qualificationtext: that.data.qualificationtext,
            // workperiod: that.data.workperiod,
            workyear: that.data.workyear,
            personperiod: that.data.personperiod,
            idCardphotos: that.data.idCardphotos.join(','),
			isread:that.data.isread
        }

        let url = app.u.HOME_URL + app.u.PSY_APPLY
        api.requestUrl(data, url).then(res => {
            if (res.code == 200) {
                that.setData({
                    step: 2
                })
                let data = { id: res.data.id }
                let consultid = res.data.id;
                let url = app.u.HOME_URL + app.u.PSY_OTHER
                api.requestUrl(data, url).then(res => {
                    if (res.code == 200) {
                        that.setData({
                            education: res.data.education,
                            train: res.data.train,
                            pexps: res.data.pexp,
                            supexps: res.data.supexp,
                            consultid: consultid,
                        })
                    } else {
                        api.showError(res.msg)
                    }
                })
            } else {
                api.showError(res.msg)
            }
        })

    },
    /**
     * step2
     * @param {*} options 
     */
    zcancel: function(e) {
        this.setData({
            addtype: 0,
            start_date: '',
            end_date: '',
            school: '',
            major: '',
            educate: '',
            intro: '',
        })
    },
    bindstartDateChange: function(e) {
        this.setData({
            start_date: e.detail.value
        })
    },
    bindendDateChange: function(e) {
        this.setData({
            end_date: e.detail.value
        })
    },
    schoolInput: function(e) {
        this.setData({
            school: e.detail.value
        })
    },
    majorInput: function(e) {
        this.setData({
            major: e.detail.value
        })
    },
    educationInput: function(e) {
        this.setData({
            educate: e.detail.value
        })
    },
    hoursInput: function(e) {
        this.setData({
            hours: e.detail.value
        })
    },
    forwardsInput: function(e) {
        this.setData({
            forwards: e.detail.value
        })
    },
    supnameInput: function(e) {
        this.setData({
            supname: e.detail.value
        })
    },
    leadingInput: function(e) {
        this.setData({
            leading: e.detail.value
        })
    },
    leadnameInput: function(e) {
        this.setData({
            leadname: e.detail.value
        })
    },
    leadphoneInput: function(e) {
        this.setData({
            leadphone: e.detail.value
        })
    },
    addeducate: function(e) {
        this.setData({
            addtype: e.currentTarget.dataset.addtype,
            start_date: '',
            end_date: '',
            school: '',
            major: '',
            educate: '',
            id: 0,
            educatephotos: []
        })
    },
    qualificate: function(e) {
        this.setData({
            addtype: e.currentTarget.dataset.addtype,
        })
    },
    addtrain: function(e) {
        this.setData({
            addtype: e.currentTarget.dataset.addtype,
            start_date: '',
            end_date: '',
            intro: '',
            id: 0,
            hours: '',
			theme: '',
			leader: '',
            trainphotos: []
        })
    },
    addpexp: function(e) {
        this.setData({
            addtype: e.currentTarget.dataset.addtype,
            start_date: '',
            end_date: '',
            intro: '',
            id: 0,
            hours: '',
            pexpphotos: [],
            leading: '',
            leadphone: '',
            leadname: '',
        })
    },
    addsupexp: function(e) {
        this.setData({
            addtype: e.currentTarget.dataset.addtype,
            start_date: '',
            end_date: '',
            intro: '',
            id: 0,
            hours: '',
            supexpphotos: [],
            supname: '',
            forwards: '',
        })
    },
    introInput: function(e) {
        this.setData({
            intro: e.detail.value,
        })
    },
    confirm: function() {
        let that = this
        if (that.data.addtype == 1) {
            if (that.data.start_date == '') {
                api.showError('请选择开始时间')
                return false
            }
            if (that.data.end_date == '') {
                api.showError('请选择结束时间')
                return false
            }
            if (that.data.school == '') {
                api.showError('请填写学校')
                return false
            }
            if (that.data.major == '') {
                api.showError('请填写专业')
                return false
            }
            if (that.data.educate == '') {
                api.showError('请填写学位')
                return false
            }
            if (that.data.educatephotos.length == 0) {
                api.showError('请上传证明材料')
                return false
            }
            let data = {
                consultant_id: that.data.consultid,
                start_date: that.data.start_date,
                end_date: that.data.end_date,
                school: that.data.school,
                major: that.data.major,
                educate: that.data.educate,
                account_id: that.data.accountid,
                photos: that.data.educatephotos.join(','),
                id: that.data.id
            }
            let url = app.u.HOME_URL + app.u.ADD_EDUCATION
            api.requestUrl(data, url).then(res => {
                if (res.code == 200) {
                    api.showSuccess(res.msg)
                    that.setData({
                        education: res.data
                    })
                    setTimeout(function() {
                        that.zcancel()
                    }, 1000)
                } else {
                    api.showError(res.msg)
                }
            })

        } else if (that.data.addtype == 2) {
            if (that.data.start_date == '') {
                api.showError('请选择开始时间')
                return false
            }
            if (that.data.end_date == '') {
                api.showError('请选择结束时间')
                return false
            }
            if (that.data.intro == '') {
                api.showError('请填写培训机构')
                return false
            }
			if (that.data.theme == '') {
				api.showError('请填写培训主题')
				return false
			}
			if (that.data.leader == '') {
				api.showError('请填写培训导师')
				return false
			}
            if (that.data.hours == '') {
                api.showError('请填写培训时长')
                return false
            }
            if (that.data.trainphotos.length == 0) {
                api.showError('请上传证明材料')
                return false
            }
            console.log(that.data.trainphotos)
            let data = {
                consultant_id: that.data.consultid,
                start_date: that.data.start_date,
                end_date: that.data.end_date,
                intro: that.data.intro,
                hours: that.data.hours,
				theme: that.data.theme,
				leader:that.data.leader,
                photos: that.data.trainphotos.join(','),
                account_id: that.data.accountid,
                id: that.data.id
            }
            let url = app.u.HOME_URL + app.u.ADD_TRAIN
            api.requestUrl(data, url).then(res => {
                if (res.code == 200) {
                    api.showSuccess(res.msg)
                    that.setData({
                        train: res.data
                    })
                    setTimeout(function() {
                        that.zcancel()
                    }, 1000)
                } else {
                    api.showError(res.msg)
                }
            })

        } else if (that.data.addtype == 3) {
            if (that.data.qualificationnum == '') {
                api.showError('请填写证书编号')
                return false
            }
            if (that.data.qualificationtext == '') {
                api.showError('请填写证书')
                return false
            }
            if (that.data.qualificatephotos.length == 0) {
                api.showError('请上传证书证明')
                return false
            }
            let data = {
                consultant_id: that.data.consultid,
                qualificationtext: that.data.qualificationtext,
                qualificationnum: that.data.qualificationnum,
                qualificatephotos: that.data.qualificatephotos.join(','),
                account_id: that.data.accountid,
            }
            let url = app.u.HOME_URL + app.u.ADD_QUALIFICATE
            api.requestUrl(data, url).then(res => {
                if (res.code == 200) {
                    api.showSuccess(res.msg)
                    that.setData({
                        train: res.data
                    })
                    setTimeout(function() {
                        that.zcancel()
                    }, 1000)
                } else {
                    api.showError(res.msg)
                }
            })
        } else if (that.data.addtype == 4) {

            if (that.data.intro == '') {
                api.showError('请填写咨询类型')
                return false
            }
            if (that.data.start_date == '') {
                api.showError('请选择开始时间')
                return false
            }
            if (that.data.end_date == '') {
                api.showError('请选择结束时间')
                return false
            }
            if (that.data.hours == '') {
                api.showError('请填写时间')
                return false
            }
            if (that.data.leadname == '') {
                api.showError('请填写机构名称')
                return false
            }
            if (that.data.leading == '') {
                api.showError('请填写负责人')
                return false
            }
            if (that.data.leadphone == '') {
                api.showError('请填写机构电话')
                return false
            }
            if (that.data.pexpphotos.length == 0) {
                api.showError('请上传证明材料')
                return false
            }
            let data = {
                consultant_id: that.data.consultid,
                start_date: that.data.start_date,
                end_date: that.data.end_date,
                leadname: that.data.leadname,
                intro: that.data.intro,
                hours: that.data.hours,
                leading: that.data.leading,
                leadphone: that.data.leadphone,
                leading: that.data.leading,
                account_id: that.data.accountid,
                photos: that.data.pexpphotos.join(','),
                id: that.data.id
            }
            let url = app.u.HOME_URL + app.u.ADD_PEXP
            api.requestUrl(data, url).then(res => {
                if (res.code == 200) {
                    api.showSuccess(res.msg)
                    that.setData({
                        pexps: res.data
                    })
                    setTimeout(function() {
                        that.zcancel()
                    }, 1000)
                } else {
                    api.showError(res.msg)
                }
            })
        } else if (that.data.addtype == 5) {

            if (that.data.intro == '') {
                api.showError('请填写督导类型')
                return false
            }
            if (that.data.start_date == '') {
                api.showError('请选择开始时间')
                return false
            }
            if (that.data.end_date == '') {
                api.showError('请选择结束时间')
                return false
            }
            if (that.data.supname == '') {
                api.showError('请填写督导姓名')
                return false
            }
            if (that.data.forwards == '') {
                api.showError('请填写督导方向')
                return false
            }
            if (that.data.hours == '') {
                api.showError('请填写时间')
                return false
            }

            if (that.data.supexpphotos[0] == '') {
                api.showError('请上传证明材料')
                return false
            }
            let data = {
                consultant_id: that.data.consultid,
                start_date: that.data.start_date,
                end_date: that.data.end_date,
                leadname: that.data.leadname,
                intro: that.data.intro,
                hours: that.data.hours,
                supname: that.data.supname,
                forwards: that.data.forwards,
                account_id: that.data.accountid,
                photos: that.data.supexpphotos.join(','),
                id: that.data.id
            }
            let url = app.u.HOME_URL + app.u.ADD_SUPEXP
            api.requestUrl(data, url).then(res => {
                if (res.code == 200) {
                    api.showSuccess(res.msg)
                    that.setData({
                        pexps: res.data
                    })
                    setTimeout(function() {
                        that.zcancel()
                    }, 1000)
                } else {
                    api.showError(res.msg)
                }
            })
        }
    },
    educateview: function(e) {
        let that = this
        let touchTime = this.data.touch_end - this.data.touch_start
        let index = e.currentTarget.dataset.index
        let id = e.currentTarget.dataset.id
        if (touchTime > 350) {
            let that = this
            wx.showModal({
                title: '提示',
                content: '确定要删除该教育经历？',
                success(res) {
                    if (res.confirm) {
                        let url = app.u.HOME_URL + app.u.CONSULTANT_DEL
                        let data = { id: id, type: 1, account_id: that.data.account_id }
                        api.requestUrl(data, url).then(res => {
                            if (res.code == 200) {
                                that.setData({
                                    education: res.data
                                })
                            } else {
                                api.showError(res.msg)
                            }
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消')
                    }
                }
            })
        } else {
            let index = e.currentTarget.dataset.index
            that.setData({
                id: that.data.education[index].id,
                start_date: that.data.education[index].start_date,
                end_date: that.data.education[index].end_date,
                school: that.data.education[index].school,
                major: that.data.education[index].major,
                educate: that.data.education[index].education,
                educatephotos: that.data.education[index].photos,
                addtype: 1
            })
        }
    },
    trainview: function(e) {
        let that = this
        let touchTime = this.data.touch_end - this.data.touch_start
        let index = e.currentTarget.dataset.index
        let id = e.currentTarget.dataset.id
        if (touchTime > 350) {
            let that = this
            wx.showModal({
                title: '提示',
                content: '确定要删除培训？',
                success(res) {
                    if (res.confirm) {
                        let url = app.u.HOME_URL + app.u.CONSULTANT_DEL
                        let data = { id: id, type: 2, account_id: that.data.account_id }
                        api.requestUrl(data, url).then(res => {
                            if (res.code == 200) {
                                that.setData({
                                    train: res.data
                                })
                            } else {
                                api.showError(res.msg)
                            }
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消')
                    }
                }
            })
        } else {
            let index = e.currentTarget.dataset.index
            that.setData({
                id: that.data.train[index].id,
                start_date: that.data.train[index].start_date,
                end_date: that.data.train[index].end_date,
                // school: that.data.train[index].start_date,
				leader: that.data.train[index].leader,
				theme: that.data.train[index].theme,
                intro: that.data.train[index].intro,
                trainphotos: that.data.train[index].photos,
                hours: that.data.train[index].hours,
                addtype: 2
            })
        }
    },
    pexpview: function(e) {
        let that = this
        let touchTime = this.data.touch_end - this.data.touch_start
        let index = e.currentTarget.dataset.index
        let id = e.currentTarget.dataset.id
        if (touchTime > 350) {
            let that = this
            wx.showModal({
                title: '提示',
                content: '确定要删除培训？',
                success(res) {
                    if (res.confirm) {
                        let url = app.u.HOME_URL + app.u.CONSULTANT_DEL
                        let data = { id: id, type: 3, account_id: that.data.account_id }
                        api.requestUrl(data, url).then(res => {
                            if (res.code == 200) {
                                that.setData({
                                    pexps: res.data
                                })
                            } else {
                                api.showError(res.msg)
                            }
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消')
                    }
                }
            })
        } else {
            let index = e.currentTarget.dataset.index
            that.setData({
                id: that.data.pexps[index].id,
                start_date: that.data.pexps[index].start_date,
                end_date: that.data.pexps[index].end_date,
                leadname: that.data.pexps[index].leadname,
                intro: that.data.pexps[index].intro,
                hours: that.data.pexps[index].hours,
                leading: that.data.pexps[index].leading,
                leadphone: that.data.pexps[index].leadphone,
                pexpphotos: that.data.pexps[index].photos,
                addtype: 4
            })
        }
    },
    supexpview: function(e) {
        let that = this
        let touchTime = this.data.touch_end - this.data.touch_start
        let index = e.currentTarget.dataset.index
        let id = e.currentTarget.dataset.id
        if (touchTime > 350) {
            let that = this
            wx.showModal({
                title: '提示',
                content: '确定要删除培训？',
                success(res) {
                    if (res.confirm) {
                        let url = app.u.HOME_URL + app.u.CONSULTANT_DEL
                        let data = { id: id, type: 5, account_id: that.data.account_id }
                        api.requestUrl(data, url).then(res => {
                            if (res.code == 200) {
                                that.setData({
                                    supexps: res.data
                                })
                            } else {
                                api.showError(res.msg)
                            }
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消')
                    }
                }
            })
        } else {
            let index = e.currentTarget.dataset.index
            console.log(that.data.supexps[index])
            that.setData({
                id: that.data.supexps[index].id,
                start_date: that.data.supexps[index].start_date,
                end_date: that.data.supexps[index].end_date,
                forwards: that.data.supexps[index].forwards,
                intro: that.data.supexps[index].intro,
                hours: that.data.supexps[index].hours,
                supname: that.data.supexps[index].supname,
                supexpphotos: that.data.supexps[index].photos,
                addtype: 5
            })
        }
    },
    next: function(e) {
        this.setData({
            step: e.currentTarget.dataset.step
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this
        cropper.init.apply(that, [W, H]);
    },
    finish: function() {
        api.showSuccess('提交成功')
        setTimeout(function() {
            wx.switchTab({
                url: '../index/index',
            })
        }, 1000)
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        if (a) {
            a = false;
            return;
        }
        if (this.isFromShare) return;
        let that = this
        let consultid = 0
        wx.getStorage({
            key: 'userInfo',
            success: function(res) {
                if (res.data.consult) {
                    consultid = res.data.consult.id
                }
                let accountid = res.data.id
                let cover = res.data.cover
                let data = { id: consultid }
                let url = app.u.HOME_URL + app.u.PSY_TAGS
                api.requestUrl(data, url).then(res => {
                    if (res.code == 200) {
                        that.setData({
                            psy_consult: res.data.psy_consult,
                            factions_list: res.data.factions_list,
                            // tag_list: res.data.tag_list,
                            // tag_type_list: res.data.tag_type_list,
                            // tags_time: res.data.tags_time,
                            avatar: cover,
                            consultid: consultid,
                            accountid: accountid,
                            arealist: res.data.area,
                        })
                        if (res.data.record.name) {

                            // if (res.data.record.avatar) {
                            //     that.setData({
                            //         avatar: res.data.record.avatar,
                            //     })
                            // }
                            // if (res.data.record.price) {
                            //     that.setData({
                            //         price: res.data.record.price,
                            //     })
                            // }
                            if (res.data.record.citylist) {
                                that.setData({
                                    citylist: res.data.record.citylist,
                                })
                            }
                            if (res.data.record.provincename) {
                                that.setData({
                                    provincename: res.data.record.provincename,
                                })
                            }
                            if (res.data.record.cityname) {
                                that.setData({
                                    cityname: res.data.record.cityname,
                                })
                            }
                            that.setData({
                                // step1 数据
                                // goodat_ids: res.data.record.goodat_ids,
                                // qualification: res.data.record.qualification,
                                // type_ids: res.data.record.type_ids,
                                factions_ids: res.data.record.factions_ids,
                                // intro: res.data.record.intro,
                                // islow: res.data.record.islow,
                                // priceintro: res.data.record.priceintro,
                                // forviewer: res.data.record.forviewer,
                                // worktype: res.data.record.worktype,
                                // period_ids: res.data.record.period_ids,
                                // ntype_ids: res.data.record.ntype_ids,
                                nfactions_ids: res.data.record.nfactions_ids,
                                // ngoodat_ids: res.data.record.ngoodat_ids,
                                // nperiod_ids: res.data.record.nperiod_ids,

                                province_id: res.data.record.province_id,
                                city_id: res.data.record.city_id,
                                name: res.data.record.name,
                                qualificationphotos: res.data.record.qualificationphotos,
                                qualificationtext: res.data.record.qualificationtext,
                                qualificationnum: res.data.record.qualificationnum,
                                avatar: res.data.record.avatar,
                                idCardphotos: res.data.record.idCardphotos,
                                workperiod: res.data.record.workperiod,
                                workyear: res.data.record.workyear,
                                personperiod: res.data.record.personperiod,
								isread:res.data.record.isread
                            })
                        }
                    } else {
                        api.showError(res.msg)
                    }
                })
            }
        })
    },
	radioChange(e) {
		this.setData({
			isread: 1
		})
		
	},
	isread(e){
		wx.navigateTo({
			url: '/pages/thetext/thetext?id=158',
		})
	}
})